<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang="en">
<head>
<meta name="copyright" content="Copyright (c) IBM Corporation and others 2000, 2017. This page is made available under license. For full details see the LEGAL in the documentation book that contains this page." >
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="stylesheet" href="../book.css" charset="ISO-8859-1" type="text/css">
<title> Debugging your programs </title>
</head>
<body>
<h1> Debugging your programs </h1>
<p> In this section, you will debug a Java program. </p>
<ol>
  <li> In the Package Explorer view in the Java perspective, double-click <em>junit.samples/VectorTest.java</em> 
    to open it in an editor. </li>
  <li> Place your cursor on the vertical ruler along the left edge of the editor
    area on the following line in the setUp() method: 
    <p> <code>fFull.addElement (new Integer(1));</code> </p>
    <p> and double-click on the ruler to set a breakpoint. </p>
    <p> <img src="images/editor_vectortest_debug.png"  alt="VectorTest.java editor showing added breakpoint"> 
    </p>
    The breakpoint icon indicates the status of the breakpoint.&nbsp; The plain
    blue breakpoint icon indicates that the breakpoint has been set, but not yet
    installed.&nbsp;&nbsp;
    <p>
    <em>Note: Once the class is loaded by the Java VM, the breakpoint will be
    installed and a checkmark overlay will be displayed on the breakpoint icon.</em> </p></li>
  <li> In the Package Explorer view, select the <em>junit.samples</em> package 
    and select <strong>Debug As</strong>, and then <strong>Java 
    Application</strong>.&nbsp; When you run a program from a package, you will be
    prompted to choose a type from all classes in the package that define a <code>main
    </code>method.&nbsp; </li>
  <li> Select the <em>VectorTest</em> item in the dialog, 
    then click <strong>OK</strong>. 
    <p> <img src="images/select_java_app_dialog.png"  alt="Type selection dialog"> </p>
    <p><em>Note: You can also simply hit the debug button <img src="images/debug_button.png" alt="Debug button"> 
      which will launch the currently selected resource or active editor. Select 
      <strong>Java Application </strong>when you are prompted to select a way 
      to debug VectorTest.</em></p>
	  <p><img src="images/select_how.png" alt="Select way to debug VectorTest"></p>
  </li>
  <li> The program will run until the breakpoint is reached.&nbsp; When the breakpoint is hit, execution 
    is suspended, and you are asked whether to open the Debug perspective.  Click <strong>Yes</strong>.
    Notice that the process is still active (not terminated) in 
    the Debug view. Other threads might still be running.
    <p> <img src="images/workbench_debug_vectortest.png"  alt="Debug perspective"> </p>
    <em>Note: The breakpoint now has a checkmark overlay <img src="images/active_break_point.png" alt="Breakpoint with overlay"> since the class
    VectorTest was loaded in the Java VM.</em> </li>
  <li> In the editor in the Debug perspective, select <code>new Vector()</code> from the line above
    where the breakpoint is set, and from its context menu, select <strong>Inspect</strong>. 
    <p> <img src="images/editor_vectortest_inspect.png"  alt="VectorTest.java editor with selected breakpoint line showing context menu"> 
    </p>
  </li>
  <li> The expression is evaluated in the context of the current stack frame, 
    and a pop-up appears which displays the results. You can send a result to
    the Expressions view by pressing the key binding displayed in the pop-up.
  </li>
  <li> Expressions that you evaluate while debugging a program will be listed in
    this view. To delete an expression after working with it, select the
    expression and choose <strong>Remove</strong> from its context menu. 
  </li>
  <li> The Variables view (available on a tab along with the Expressions view) displays the values of the variables in the selected 
    stack frame. Expand the this.fFull tree in the Variables view until you can see 
    value. 
  </li>
  <li> The variables (e.g., no of elements) in the Variables view will change when
    you step 
    through VectorTest in the Debug view.&nbsp; To step through the code, click the 
    <strong>Step Over</strong> (<img src="../images/org.eclipse.debug.ui/elcl16/stepover_co.svg" alt="Step Over" >) button.&nbsp;
    Execution will continue at the next line in the same method 
      (or, if you are at the end of a method, it will continue in the method from 
      which the current method was called).
      <p> <img src="images/view_variables_logical_structures.png" alt="fFull shown as logical structure"> </p>
  </li>
  <li>The variables view shows certain types as Logical Structures.You can define logical structures by yourself in the preference page <strong>Java &gt; Debug &gt; Logical Structures</strong>.

   </li>
   <li><p>You can choose to disable <strong>Show Logical Structure</strong><img src="images/view_variables_logical_structure_action.svg" alt="Logical structure action"> to show the implementation details of these types.</p>
       <p> <img src="images/view_variables_1.png" alt="fFull shown as details"> </p>
  </li>
  <li> Try some other step buttons 
    (<strong>Step Into <img src="../images/org.eclipse.debug.ui/elcl16/stepinto_co.svg" alt="Step Into" >, 
    Step Return <img src="../images/org.eclipse.debug.ui/elcl16/stepreturn_co.svg" alt="Step Return" >) </strong>to
    step through the code.&nbsp; Note the differences in stepping techniques.
  </li>
  <li> You can end a debugging session by allowing the program to run to
    completion or by terminating it.
    <ul>
      <li>You can continue to step over the code with the <strong>Step </strong>buttons
        until the program completes.</li>
      <li>You can click the&nbsp; <strong>Resume </strong>  
      (<img src="../images/org.eclipse.debug.ui/elcl16/resume_co.svg" alt="Resume" >) button to allow the
        program to run until the next breakpoint is encountered or until the
        program is completed.</li>
      <li>You can select 
    <strong>Terminate</strong> from the context menu of the program's
        process in the Debug view to terminate the program.</li>
    </ul>
  </li>
</ol>
<P class="nav_footer" id="nav_footer">Next Section: <A href="qs-14.htm">Evaluating expressions</A>
</P>
    <h3 class="related">Related concepts</h3>
     <a href="../concepts/cbrkpnts.htm">Breakpoints</a><br>
     <a href="../concepts/cremdbug.htm">Remote debugging</a><br>
     <a href="../concepts/clocdbug.htm">Local debugging</a>

    <h3 class="related">Related tasks</h3>
     <a href="../tasks/task-add_line_breakpoints.htm">Adding breakpoints</a><br>
     <a href="../tasks/task-resuming_threads.htm">Resuming the execution of suspended threads</a><br>
     <a href="../tasks/task-running_and_debugging.htm">Running and debugging</a><br>
     <a href="../tasks/task-suspending_threads.htm">Suspending threads</a>

    <h3 class="related">Related references</h3>
     <a href="../reference/preferences/java/debug/ref-debug.htm">Debug preferences</a><br>
     <a href="../reference/views/debug/ref-debug_view.htm">Debug view</a><br>
     <a href="../reference/menus/run/ref-menu-run.htm">Run menu actions</a><br>
     <a href="../reference/ref-toolbar-run.htm">Run and debug toolbar actions</a><br>
     <a href="../reference/views/breakpoints/ref-breakpoints_view.htm">Breakpoints view</a><br>
     <a href="../reference/views/console/ref-console_view.htm">Console view</a><br>
     <a href="../reference/views/display/ref-debug_shell_view.htm">Debug shell view</a><br>
     <a href="../reference/views/expressions/ref-expressions_view.htm">Expressions view</a><br>
     <a href="../reference/views/variables/ref-variables_view.htm">Variables view</a>

</body>
</html>

